package com.kang.delay;

import com.kang.utils.RabbitMQUtils;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: zhangkangkang
 * @Description: 延迟队列，给不同的消息设置不同的过期时间
 * @date 2021/8/3 15:02
 */
public class Consumer {
    public static void main(String[] args) throws IOException, InterruptedException {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("queuedelay", false, false, false, null);

        channel.basicConsume("queuedelay", true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者延时接到" + System.currentTimeMillis() + new String(body));
            }
        });
    }
}
